package com.ykt.model;

import com.jfinal.plugin.activerecord.Page;

import java.util.Map;

/**
 * 摄像头与店铺关系
 * @author long.hua
 * @version 1.0.0
 * @since 2016-01-09 21:49
 */
public class CameraShop extends BaseModel<CameraShop>{
	private static final long serialVersionUID = 1L;

    public static final String shop_id = "shop_id";
    public static final String camera_id = "camera_id";

    public final static CameraShop dao = new CameraShop();


	@Override
    public Page<CameraShop> pageFindModel(int pageNumber, int rows, Map<String, String> paramMap) {
        String select = "SELECT c.device_serial, c.device_name, c.camera_no, c.camera_name, c.status, a.id, s.name shop_name ";
        String sqlExceptSelect = "FROM camera_shop a "
        		+ " LEFT JOIN camera c ON a.camera_id = c.id "
        		+ " LEFT JOIN shop s ON a.shop_id = s.id ";
        paramMap.put("EQ_s.id", paramMap.get("s.id"));
        return this.pageFindModel(select, sqlExceptSelect, pageNumber, rows, paramMap);
    }

    public int save(int shopId, int cameraId){
        boolean flag = this.set("shopId", shopId).set("cameraId", cameraId).save();
        if(flag){
            return dao.get("id");
        } else {
            return -1;
        }
    }
}
